from pickle import load as _load, dump as _dump
from os import system as _system

from numpy import ndarray

# from ipdb import set_trace as _set_trace

__all__ = [
    # "trace",
    "llist",
    "cmd",
    "p",
    "save",
    "saveValue",
    "loadValue",
    "taskill",
]


# def trace() -> None:
#     """从触发起，逐行追踪代码的执行"""
#     _set_trace()


def llist(lst) -> str:
    return '\n'.join([str(i) for i in lst])


def cmd(command) -> None:
    """CMD命令行"""
    return _system(f"cmd /c {command}")


def taskill(fn: str = ''):
    """杀进程"""
    _system(f"taskkill /im {fn}")


def p(*lst, **dic) -> None:
    """快速打印调试"""
    for i in lst:
        print(i, type(i), sep='\n')
        if isinstance(i, ndarray):
            print(f"shape: {i.shape}")
            print(f"dtype: {i.dtype}")
        if isinstance(i, list):
            print(f"len: {len(i)}")
        print("\n")
    for k, v in dic.items():
        print(type(k), k, type(v), v, sep='\n', end="\n\n")


def save(box: list, msg: str = ">Input:", types: list = None):
    if types is None:
        types = [str]
    temp = input(msg)
    if temp:
        for i in range(len(types)):
            try:
                box[i] = types[i](temp)
            except Exception:
                box.append(types[i](temp))
    return temp


def saveValue(fp: str, value) -> None:
    """把值存到文件里面"""
    with open(fp, mode="wb") as f:
        o = _dump(value, f)


def loadValue(fp: str):
    """从文件中取出值"""
    with open(fp, mode="rb") as f:
        return _load(f)
